﻿using Es.Abp.Domain.Entities;
using Es.Abp.Domain.IRepository;
using SqlSugar;
using Volo.Abp.DependencyInjection;

namespace Es.Abp.SqlSugarCore
{
    /// <summary>
    /// ITransientDependency有大坑
    /// </summary>
    public class StudentRepository : IStudentRepository, ITransientDependency
    {
        private ISqlSugarClient _db;
        public StudentRepository(ISqlSugarClient db) { _db = db; }
        public async Task<List<StudentEntity>> GetStudentAsync()
        {
            var r = await _db.Queryable<StudentEntity>().ToListAsync();
            return r;
        }

        public async Task<StudentEntity> CreateStudentAsync(StudentEntity entity)
        {
            await _db.Insertable(entity).ExecuteCommandIdentityIntoEntityAsync();
            return entity;
        }

        public object InitTableAsync()
        {
            _db.CodeFirst.InitTables<StudentEntity>();
            return new { Result = true };
        }
    }
}
